import 'dart:convert';
import 'dart:ui';

import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'i18n_zh_cn.dart';
import 'i18n_en_us.dart';

extension StringExtension on String {
  String get trx => tr;
}

// 简体中文 zh_CN
// 德语 de_DE
// 英语 en_US
class I18nConfig extends Translations {
  @override
  Map<String, Map<String, String>> get keys => {'zh_CN': i18n_zh_cn, 'en_US': i18n_en_us};




  static final Map<String, Map<String, String>> _translatedValues = {};

  static Future<void> load() async {
    // _translatedValues['en_US'] = await _load(Assets.translationsEnUS);
    // _translatedValues['zh_CN'] = await _load(Assets.translationsZhCN);
  }

  // 加载json文件
  static Future<Map<String, String>> _load(String path) async {
    final jsonString = await rootBundle.loadString(path);
    final jsonMap = jsonDecode(jsonString) as Map<String, dynamic>;
    return Map<String, String>.fromEntries(jsonMap.entries.map((entry) {
      return MapEntry(entry.key, entry.value.toString());
    }));
  }

  // 切换语言
  static switchLanguage(Locale locale) {
    //这个是使用系统语言
    ///import 'dart:ui' as ui;
    //
    // return GetMaterialApp(
    //     locale: ui.window.locale,
    // );
    // if (Get.locale == Locale('en', 'US')) {
    Get.updateLocale(locale);
  }
}
